package com.tingyuge.base.structrue.node;

/**
 * @Created by xiaodao
 */
public class LinkedListStack<E> implements Stack<E> {

    private LinkedList<E> linkedList;

    public LinkedListStack(LinkedList<E> linkedList) {
        this.linkedList = linkedList;
    }

    @Override
    public int getSize() {
        return linkedList.getSize();
    }

    @Override
    public boolean isEmpty() {
        return linkedList.isEmpty();
    }

    @Override
    public void push(E e) {
        linkedList.addFirst(e);
    }

    @Override
    public E peek() {
        return linkedList.get(0);
    }

    @Override
    public E pop() {
        return linkedList.removeFirst();
    }

    @Override
    public String toString() {

        StringBuilder builder = new StringBuilder();
        builder.append("stack top : ");
        builder.append(linkedList);
       return builder.toString();
    }
}
